package com.suda.sudaexamsystem.controller;

import com.suda.sudaexamsystem.service.QuestionTypeService;
import com.suda.sudaexamsystem.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("type")
public class QuestionTypeController {
    @Autowired
    private QuestionTypeService questionTypeService;

    // 获取指定类型
    //{"msg":"操作成功","code":200,"data":{"id":1,"name":"选择题"}}
    @GetMapping(value = "/get/{typeId}", produces = {"application/json;charset=UTF-8"})
    public AjaxResult getType(@PathVariable("typeId") int typeId) {
        // questionType没有和任何建立关系  不会引起循环依赖 不需要Dto
        return AjaxResult.success(questionTypeService.findById(typeId));
    }

    // 获取所有类型
    //{"msg":"操作成功","code":200,"data":[{"id":1,"name":"选择题"},{"id":2,"name":"填空题"},
    // "id":3,"name":"判断题"},{"id":4,"name":"简答题"}]}
    @GetMapping(value = "/getAll", produces = {"application/json;charset=UTF-8"})
    public AjaxResult getTypes() {
        return AjaxResult.success(questionTypeService.findAll());
    }
}
